﻿using CSharpDesign.DAL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;

namespace CSharpDesign.BLL
{
    public class OrderStatisticsService
    {
        /// <summary>
        /// 鼠标移动变色
        /// </summary>
        /// <param name="e"></param>
        public static void Color(GridViewRowEventArgs e)
        {
            //鼠标移动变色
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
                e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#f6f6f6',this.style.fontWeight='';");
                //当鼠标离开的时候 将背景颜色还原的以前的颜色 
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
            }
            //单击行改变行背景颜色 
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onclick", "this.style.backgroundColor='#f6f6f6'; this.style.color='buttontext';this.style.cursor='default';");
            }
        }
        public static string Select_Strtop(int iCount, string SPName, string txttime, string Text1)
        {
            string strTop = "";
            if (iCount > 1)
            {
                strTop = "top " + iCount.ToString();
            }

            string str = "";
            string sql = str;
            sql = "select  " + strTop + "  shuliang*SPPrice as Zong ,* from [vb_OrderInfo] where  1=1  ";



            if (SPName != "")
            {
                sql += " and   SPName   like   '%" + SPName + "%'   ";
            }
            if (txttime != "")
            {
                sql += " and   OrderDate   between    '" + txttime + "' and  '" + Text1 + "'   ";
            }

            return sql;
        }
        public static DataSet Sql_con(string sql)
        {
            SqlHelper date = new SqlHelper();
            SqlConnection con = new SqlConnection(SqlHelper.connstring);
            SqlCommand cmd = new SqlCommand(sql, con);

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = null;
            try
            {
                con.Open();
                ds = new DataSet();
                da.Fill(ds);

            }
            catch (SqlException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
            return ds;
        }
        /// <summary>
        /// 查询订单总数
        /// </summary>
        /// <param name="SPName"></param>
        /// <param name="txttime"></param>
        /// <param name="Text1"></param>
        /// <returns></returns>
        public static string Select_Sum(string SPName, string txttime, string Text1)
        {
            string sql = "select    sum(shuliang*SPPrice) as Zong  from [vb_OrderInfo] where  1=1 ";
            if (SPName != "")
            {
                sql += " and   SPName   like   '%" + SPName + "%'   ";
            }
            if (txttime != "")
            {
                sql += " and   OrderDate   between    '" + txttime + "' and  '" + Text1 + "'   ";
            }

            return sql;
        }
        /// <summary>
        /// 提示结果
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static string Result_Tip(string sql)
        {
            SqlHelper data = new SqlHelper();
            SqlDataReader dr = data.GetDataReader(sql);
            if (dr.Read())
            {
                string zong= dr["zong"].ToString();
                return zong;
            }
            else
            {
                return "0";
            }
        }
    }
}